﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using MvcApplication6.DAL.Helper;
using MvcApplication6.Models;


namespace MvcApplication6.DAL
{
    public class SalePersonDAL
    {
        //---------------------SalePersonSearch-----------------------------
        public List<SalePersonModel> SalePersonSearch()
        {

            List<SalePersonModel> lst = new List<SalePersonModel>();

            SalePersonModel obj = null;

            SqlDataReader dr = SQLHelper.ExecuteReader("spSalePersonSearch");
            while (dr.Read())
            {
                obj = new SalePersonModel();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.phone = dr["phone"].ToString();
                obj.skype = dr["skype"].ToString();
                obj.yahoo = dr["yahoo"].ToString();

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //-------------------SalePersonById-------------------
        public SalePersonModel SalePersonSearchById(int id)
        {
            SalePersonModel obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spSalePersonSearchById", parameterList);

            while (dr.Read())
            {
                obj = new SalePersonModel();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.phone = dr["phone"].ToString();
                obj.skype = dr["skype"].ToString();
                obj.yahoo = dr["yahoo"].ToString();

            }
            dr.Close();
            return obj;
        }

        //---------------------SalePersonInsert-----------------------------
        public int SalePersonInsert(string phone, string skype, string yahoo)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@phone", phone));
            parameterList.Add(new SqlParameter("@skype", skype));
            parameterList.Add(new SqlParameter("@yahoo", yahoo));

            int i = SQLHelper.ExecuteNonQuery("spSalePersonInsert", parameterList);

            return i;
        }

        //---------------------SalePersonUpdate-----------------------------
        public int SalePersonUpdate(int id, string phone, string skype, string yahoo)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@phone", phone));
            parameterList.Add(new SqlParameter("@skype", skype));
            parameterList.Add(new SqlParameter("@yahoo", yahoo));

            int i = SQLHelper.ExecuteNonQuery("spSalePersonEdit", parameterList);

            return i;
        }

        //---------------------SalePersonDelete-----------------------------
        public int SalePersonDelete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spSalePersonDelete", parameterList);

            return i;
        }
    }
}